package DesignPattern;

public class AbstractFactoryPattern {

    // 定义Product接口
    public interface Product {
        void use();
    }

    // 定义ConcreteProductA类
    public class ConcreteProductA implements Product {
        @Override
        public void use() {
            System.out.println("抽象工厂模式Using ConcreteProductA");
        }
    }

    // 定义ConcreteProductB类
    public class ConcreteProductB implements Product {
        @Override
        public void use() {
            System.out.println("抽象工厂模式Using ConcreteProductB");
        }
    }

    // 定义AbstractFactory接口
    public interface AbstractFactory {
        Product createProduct();
    }

    // 定义ConcreteFactoryA类
    public class ConcreteFactoryA implements AbstractFactory {
        @Override
        public Product createProduct() {
            return new ConcreteProductA();
        }
    }

    // 定义ConcreteFactoryB类
    public class ConcreteFactoryB implements AbstractFactory {
        @Override
        public Product createProduct() {
            return new ConcreteProductB();
        }
    }
}


